bring static functions into googltakeout class. (#1240)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Thu, 23 Nov 2023 13:24:49 +0000 (06:24 -0700)
committerGitHub <noreply@github.com>
Thu, 23 Nov 2023 13:24:49 +0000 (06:24 -0700)
and other tidy modernizations.

googletakeout.cc
googletakeout.h

index eb061239dc958d18648fdee5ff50ffbd42dd4713..5ba243c83984242006a441be1ec40a7da5233be2 100644 (file)
 #include "src/core/file.h"      // for File
 #include "src/core/logging.h"   // for Debug, FatalMsg, Warning
 
-#define MYNAME "Google Takeout"
-#define TIMELINE_OBJECTS "timelineObjects"
 
-static const QList<QString> takeout_month_names{
-  "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY",
-  "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
-};
-
-static void takeout_fatal(const QString& message) {
+void GoogleTakeoutFormat::takeout_fatal(const QString& message) {
   fatal(FatalMsg() << MYNAME << ": " << message);
 }
 
-static void takeout_warning(const QString& message) {
+void GoogleTakeoutFormat::takeout_warning(const QString& message) {
   Warning() << MYNAME << ": " << message;
 }
 
 /* create a waypoint from late7/lone7 and optional metadata */
-static Waypoint* takeout_waypoint(
+Waypoint* GoogleTakeoutFormat::takeout_waypoint(
   int lat_e7,
   int lon_e7,
   const QString* shortname,
@@ -81,7 +74,7 @@ static Waypoint* takeout_waypoint(
   return waypoint;
 }
 
-static bool track_maybe_add_wpt(route_head* route, Waypoint* waypoint) {
+bool GoogleTakeoutFormat::track_maybe_add_wpt(route_head* route, Waypoint* waypoint) {
   if (waypoint->latitude == 0 && waypoint->longitude == 0) {
     if (global_opts.debug_level >= 2) {
       Debug(2) << "Track " << route->rte_name << "@" <<
@@ -95,7 +88,7 @@ static bool track_maybe_add_wpt(route_head* route, Waypoint* waypoint) {
   return true;
 }
 
-static QList<QJsonObject> readJson(
+QList<QJsonObject> GoogleTakeoutFormat::GoogleTakeoutInputStream::readJson(
     const QString& source)
 {
   if (global_opts.debug_level >= 2) {
@@ -142,7 +135,7 @@ static QList<QJsonObject> readJson(
   return timeline;
 }
 
-static QList<QString> readDir(
+QList<QString> GoogleTakeoutFormat::GoogleTakeoutInputStream::readDir(
     const QString& source)
 {
   if (global_opts.debug_level >= 2) {
@@ -158,6 +151,10 @@ static QList<QString> readDir(
    * folders
    */
   if (baseName.length() == 4 && baseName.toInt() > 0) {
+    static const QList<QString> takeout_month_names{
+      "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY",
+      "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
+    };
     for (auto&& month : takeout_month_names) {
       const QString path = source + "/" + baseName + "_" + month + ".json";
       const QFileInfo info{path};
@@ -337,7 +334,6 @@ GoogleTakeoutFormat::add_activity_segment(const QJsonObject& activitySegment)
    *   TODO: do something with simplifiedRawPath
    */
   int n_points = 0;
-  Waypoint* waypoint = nullptr;
   auto* route = new route_head;
   const QJsonObject startLoc = activitySegment[START_LOCATION].toObject();
   const QJsonObject endLoc = activitySegment[END_LOCATION].toObject();
@@ -347,7 +343,7 @@ GoogleTakeoutFormat::add_activity_segment(const QJsonObject& activitySegment)
   track_add_head(route);
   QString timestamp;
   timestamp = activitySegment[DURATION][START_TIMESTAMP].toString();
-  waypoint = takeout_waypoint(
+  Waypoint* waypoint = takeout_waypoint(
     startLoc[LOCATION_LATE7].toInt(),
     startLoc[LOCATION_LONE7].toInt(),
     nullptr, nullptr,
@@ -404,7 +400,7 @@ GoogleTakeoutFormat::add_activity_segment(const QJsonObject& activitySegment)
   return n_points;
 }
 
-void GoogleTakeoutInputStream::loadSource(const QString& source) {
+void GoogleTakeoutFormat::GoogleTakeoutInputStream::loadSource(const QString& source) {
   const QFileInfo info{source};
   if (info.isDir()) {
     sources += readDir(source);
@@ -415,7 +411,7 @@ void GoogleTakeoutInputStream::loadSource(const QString& source) {
   }
 }
 
-QJsonValue GoogleTakeoutInputStream::next() {
+QJsonValue GoogleTakeoutFormat::GoogleTakeoutInputStream::next() {
   if (!timelineObjects.isEmpty()) {
     QJsonValue nextObject = timelineObjects.first();
     timelineObjects.removeFirst();
index b3489d928df868fff3336d889aadbac6ac84ec16..fcfe55aaca8e4d8e94d04a58c5ed5553bda7d79f 100644 (file)
@@ -26,7 +26,6 @@
 #include <QJsonValue>      // for QJsonValue
 #include <QList>           // for QList
 #include <QString>         // for QString
-#include <QStringLiteral>  // for qMakeStringPrivate, QStringLiteral
 #include <QVector>         // for QVector
 
 #include "defs.h"
  *
  * TODO: Allow date ranges
  */
-class GoogleTakeoutInputStream
-{
-public:
-  /* Special Member Functions */
-  GoogleTakeoutInputStream() = default;
-  GoogleTakeoutInputStream(const QString& source) : sources({source}) {}
-
-  /* Member Functions */
-
-  // Returns the next timelineObject, or a null QJsonValue if we're at the end
-  QJsonValue next();
-
-private:
-  /* Member Functions */
-
-  void loadSource(const QString& source);
-
-  /* Data Members */
-
-  QList<QString> sources;
-  QList<QJsonObject> timelineObjects;
-};
-
 /* Read-only Google Timeline Location History gpsbabel Format */
 class GoogleTakeoutFormat : public Format
 {
@@ -75,7 +51,7 @@ public:
 
   ff_type get_type() const override
   {
-   return ff_type_file;
+    return ff_type_file;
   }
 
   QVector<ff_cap> get_cap() const override
@@ -90,35 +66,68 @@ public:
 private:
   /* Constants */
 
-  const QString PLACE_VISIT = QStringLiteral("placeVisit");
-  const QString ACTIVITY_SEGMENT = QStringLiteral("activitySegment");
-  const QString ACTIVITY_TYPE = QStringLiteral("activityType");
-  const QString LOCATION = QStringLiteral("location");
-  const QString LOCATION_LATE7 = QStringLiteral("latitudeE7");
-  const QString LOCATION_LONE7 = QStringLiteral("longitudeE7");
-  const QString NAME = QStringLiteral("name");
-  const QString ADDRESS = QStringLiteral("address");
-  const QString DURATION = QStringLiteral("duration");
-  const QString START_TIMESTAMP = QStringLiteral("startTimestamp");
-  const QString START_LOCATION = QStringLiteral("startLocation");
-  const QString END_TIMESTAMP = QStringLiteral("endTimestamp");
-  const QString END_LOCATION = QStringLiteral("endLocation");
-  const QString TIMESTAMP = QStringLiteral("timestamp");
-  const QString SIMPLE_PATH = QStringLiteral("simplifiedRawPath");
-  const QString POINTS = QStringLiteral("points");
-  const QString WAYPOINT_PATH = QStringLiteral("waypointPath");
-  const QString WAYPOINTS  = QStringLiteral("waypoints");
-  // for some reason that probably only a former Google engineer knows,);
-  // we use = QStringLiteral("latE7"/"lngE7" here instead of "latitudeE7"/"longitudeE7".);
-  // +10 points for brevity, but -100 points for inconsistency.);
-  const QString LATE7 = QStringLiteral("latE7");
-  const QString LONE7 = QStringLiteral("lngE7");
+  static constexpr char MYNAME[] = "Google Takeout";
+  static constexpr char TIMELINE_OBJECTS[] = "timelineObjects";
+  static constexpr char16_t PLACE_VISIT[] = u"placeVisit";
+  static constexpr char16_t ACTIVITY_SEGMENT[] = u"activitySegment";
+  static constexpr char16_t ACTIVITY_TYPE[] = u"activityType";
+  static constexpr char16_t LOCATION[] = u"location";
+  static constexpr char16_t LOCATION_LATE7[] = u"latitudeE7";
+  static constexpr char16_t LOCATION_LONE7[] = u"longitudeE7";
+  static constexpr char16_t NAME[] = u"name";
+  static constexpr char16_t ADDRESS[] = u"address";
+  static constexpr char16_t DURATION[] = u"duration";
+  static constexpr char16_t START_TIMESTAMP[] = u"startTimestamp";
+  static constexpr char16_t START_LOCATION[] = u"startLocation";
+  static constexpr char16_t END_TIMESTAMP[] = u"endTimestamp";
+  static constexpr char16_t END_LOCATION[] = u"endLocation";
+  static constexpr char16_t TIMESTAMP[] = u"timestamp";
+  static constexpr char16_t SIMPLE_PATH[] = u"simplifiedRawPath";
+  static constexpr char16_t POINTS[] = u"points";
+  static constexpr char16_t WAYPOINT_PATH[] = u"waypointPath";
+  static constexpr char16_t WAYPOINTS [] = u"waypoints";
+  // for some reason that probably only a former Google engineer knows,;
+  // we use[] = u"latE7"/"lngE7" here instead of "latitudeE7"/"longitudeE7".;
+  // +10 points for brevity, but -100 points for inconsistency.;
+  static constexpr char16_t LATE7[] = u"latE7";
+  static constexpr char16_t LONE7[] = u"lngE7";
+
+  /* Types */
+
+  class GoogleTakeoutInputStream
+  {
+  public:
+    /* Special Member Functions */
+    GoogleTakeoutInputStream() = default;
+    GoogleTakeoutInputStream(const QString& source) : sources({source}) {}
+
+    /* Member Functions */
 
-  /* Member Functions */
+    // Returns the next timelineObject, or a null QJsonValue if we're at the end
+    QJsonValue next();
+
+  private:
+    /* Member Functions */
 
+    static QList<QJsonObject> readJson(const QString& source);
+    static QList<QString> readDir(const QString& source);
+    void loadSource(const QString& source);
+
+    /* Data Members */
+
+    QList<QString> sources;
+    QList<QJsonObject> timelineObjects;
+  };
+
+  /* Member Functions */
+  static void takeout_fatal(const QString& message);
+  static void takeout_warning(const QString& message);
+  Waypoint* takeout_waypoint(int lat_e7, int lon_e7, const QString* shortname, const QString* description, const QString* start_str);
+  static bool track_maybe_add_wpt(route_head* route, Waypoint* waypoint);
+  static void title_case(QString& title);
   void add_place_visit(const QJsonObject& placeVisit);
   int add_activity_segment(const QJsonObject& activitySegment);
-  static void title_case(QString& title);
 
   /* Data Members */